define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'meeting/index' + location.search,
                    add_url: 'meeting/add',
                    edit_url: 'meeting/edit',
                    del_url: 'meeting/del',
                    multi_url: 'meeting/multi',
                    import_url: 'meeting/import',
                    table: 'meeting',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
              
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'title', title: __('Title'), operate: 'LIKE'},
                        // {field: 'user_id', title: __('User_id')},
                  
                        {field: 'user_id', title: __('User_id'),searchList: $.getJSON("meeting/admin"),operate: 'FIND_IN_SET',formatter: function (value,row) {
                            return row.user_id_text;
                        }},
                        {field: 'meetingtime', title: __('Meetingtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                  
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1')}, formatter: Table.api.formatter.status},
                        
                        {field: 'weigh', title: __('Weigh'), operate: false},
                        
                        {field: 'buttons',width: "120px",title: __('查看'), operate: false,table: table,events: Table.api.events.operate,buttons: [
                            {name: 'addtabs',text: __('纪要内容'),title: __('纪要内容'),classname: 'btn btn-xs btn-warning btn-addtabs',icon: 'fa fa-folder-o',
                                url: 'meetingcontent/index?status={$row.status}'
                            }
                        ],
                            formatter: Table.api.formatter.buttons
                        },
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });
            $(".search input").attr('placeholder','纪要名称');
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            $(document).on("change", "#c-pid", function () {
                $.post("meeting/clss",{custom: {catId: $(this).val()},},function(result){
                    $('#c-user_id').selectPageData(result);
                    $('#c-user_id').val(i);
                    $('#c-user_id').selectPageRefresh();
                });                    
            });

            Controller.api.bindevent();
        },
        edit: function () {
            $(document).on("change", "#c-pid", function () {
                $.post("meeting/clss",{custom: {catId: $(this).val()},},function(result){
                    $('#c-user_id').selectPageData(result);
                    // $('#c-user_id').val(i);
                    // $('#c-user_id').selectPageRefresh();
                });                    
            });
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});